
clear all
cap log close
set more off
set matsize 1600
set mem 100m

global ROOT ""
global data "$ROOT/Data"
global dofiles "$ROOT/DoFiles"
global tables "$ROOT/Tables"
global figures "$ROOT/Figures"

u "$data\analysisfinal.dta", clear


global ourcluster "zone_o"

*Village variable for the village fixed effects
*vill1 is for the village in the first wave
local village "vill1"

/* USING ORIGINAL ZONES*/ 
/* First, generating interaction dummies between the shocks and women's group treatment variable */
qui {

gen wgonly_o = 1 if treatment_o==2
replace wgonly_o = 0 if treatment_o==1 | treatment_o==3 | treatment_o==4


*Shock variables
foreach y of varlist dcrop dintensity {
gen `y'_treat1 = `y'*wgonly_o
}

gen control = wg_o ==0
replace control = . if wg_o==.

foreach y of varlist dcrop dintensity {
gen `y'_control = `y'*control

}
}
*closing quietly above



*--------------------------------------------------------
*Building some variables that were not created before
*--------------------------------------------------------
gen d12_18=dfem12_18+dmale12_18
gen dmt18=dfemmt18+dmalemt18


gen dcre_ff=dcre_fam+dcre_friends

********************************************
 * Specification with village-time dummies
*********************************************
global regressors1 " ddays_oct dlt6 dsix_12 d12_18 dmt18"



*---------------------------------------------------------------
*Regressions
*----------------------------------------------------------------

matrix coeff1 = J(3,2,.)
matrix colnames coeff1 = "Incidence" "Intensity" 
matrix CI1 = J(2,2,.)
matrix colnames CI1 = "Incidence" "Intensity"
matrix rownames CI1 = ll95_shock ul95_shock 
matrix CI2=J(2,2,.)
matrix colnames CI2 = "Incidence" "Intensity"
matrix rownames CI2 = ll95_shock ul95_shock
matrix CI3=J(2,2,.)
matrix colnames CI3 = "Incidence" "Intensity"
matrix rownames CI3 = ll95_shock ul95_shock


areg dcre_ff_any dcrop dcrop_treat1         $regressors1, absorb(vill1) cluster ($ourcluster)
matrix coeff1[1,1]=e(b)[1,1]
matrix coeff1[2,1]=e(b)[1,2]
boottest dcrop , boot(wild) seed(10101) bootcl($ourcluster)
matrix CI1[1,1]=r(CI)[1,1]
matrix CI1[2,1]=r(CI)[1,2]
boottest dcrop_treat1 , boot(wild) seed(10101) bootcl($ourcluster)
matrix CI2[1,1]=r(CI)[1,1]
matrix CI2[2,1]=r(CI)[1,2]

qui areg dcre_ff_any dcrop_control dcrop_treat1  $regressors1, absorb(vill1) cluster ($ourcluster)
matrix coeff1[3,1]=e(b)[1,2]
boottest dcrop_treat1 , boot(wild) seed(10101) bootcl($ourcluster)
matrix CI3[1,1]=r(CI)[1,1]
matrix CI3[2,1]=r(CI)[1,2]

areg dcre_ff_any dshare_new dshare_new_treat1         $regressors1, absorb(vill1) cluster ($ourcluster)
matrix coeff1[1,2]=e(b)[1,1]
matrix coeff1[2,2]=e(b)[1,2]
boottest dshare_new , boot(wild) seed(10101) bootcl($ourcluster)
matrix CI1[1,2]=r(CI)[1,1]
matrix CI1[2,2]=r(CI)[1,2]
boottest dshare_new_treat1 , boot(wild) seed(10101) bootcl($ourcluster)
matrix CI2[1,2]=r(CI)[1,1]
matrix CI2[2,2]=r(CI)[1,2]

qui areg dcre_ff_any dshare_new_control dshare_new_treat1  $regressors1, absorb(vill1) cluster ($ourcluster)
matrix coeff1[3,2]=e(b)[1,2]
boottest dshare_new_treat1 , boot(wild) seed(10101) bootcl($ourcluster)
matrix CI3[1,2]=r(CI)[1,1]
matrix CI3[2,2]=r(CI)[1,2]

*barwidth(0.25) recast(bar)

set scheme s1mono

coefplot (matrix(coeff1[1,]), ci(CI1) label(Control)) (matrix(coeff1[3,]), ci(CI3) label(Treatment)) (matrix(coeff1[2,]), ci(CI2) label("Treatment Effect")),  xline(0)  ciopts(recast(rcap)) citop 
graph save "$figures/chats_diff", replace
graph export "$figures/chats_diff.pdf", replace



exit
